
package com.eascs.crm.nsEditDetail.controller;

import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.crm.nsEditDetail.entity.CustomerShopInfoEntity;
import com.eascs.crm.nsEditDetail.service.CustomerAssetInfoService;
import com.eascs.crm.nsEditDetail.service.CustomerShopInfoService;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/nsEditDetailView")
public class NsEditDetailViewController extends BaseMasterViewController {
	
	@Override
	public void preHandle() {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "loanManage1");
	}
	
	private final Logger logger = LoggerFactory.getLogger(NsEditDetailViewController.class);
	@Autowired
	private O2oLoanapplyService o2oLoanapplyService;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;
	@Autowired
	private CustomerAssetInfoService customerAssetInfoService;
	@Autowired
	CustomerShopInfoService shopInfoService;
	
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public String showDetail(String loanapplyNo) {
		logger.info("借款人信息查询，loanapply：【{}】", loanapplyNo);
		O2oLoanapplyEntity o2oLoanapplyEntity=o2oLoanapplyService.findById(loanapplyNo);
		O2oLoanUserEntity o2oLoanUserEntity=o2oLoanUserService.findById(o2oLoanapplyEntity.getLoanId(), loanapplyNo);
		CustomerShopInfoEntity shopInfoEntity = shopInfoService.queryCustomerMainShopByLoanapplyNo(loanapplyNo);// 主门店信息
		List<O2oLoanUserEntity> list=o2oLoanUserService.findSponsor(loanapplyNo);
		String spousemainId="";
		for (O2oLoanUserEntity loanuser : list) {
				spousemainId=loanuser.getId();
		}
		ViewContext.put("loanid", o2oLoanUserEntity.getId());		
		ViewContext.put("spousemainId", spousemainId);
		ViewContext.put("loanapply", o2oLoanapplyEntity);
		ViewContext.put("shopInfo", shopInfoEntity);
		ViewContext.put("assetnum", customerAssetInfoService.findAssetByloanapplyno(loanapplyNo));
		return "nsEditDetail/detail";
	}
}
